package cn.iocoder.yudao.module.erp.dal.mysql.finance.bankstatement;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.erp.controller.admin.finance.bankstatement.vo.BankStatementPageReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.finance.bankstatement.BankStatementDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.supplierfleet.SupplierFleetDO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 银行流水 Mapper
 * @author 天使管理员
 */
@Mapper
public interface BankStatementMapper extends BaseMapperX<BankStatementDO> {

    default PageResult<BankStatementDO> selectPage(BankStatementPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<BankStatementDO>()
                .likeIfPresent(BankStatementDO::getId,reqVO.getId())
                .eqIfPresent(BankStatementDO::getCurrencyType, reqVO.getCurrencyType())
                .orderByAsc(BankStatementDO::getCurrencyType)
                .orderByAsc(BankStatementDO::getCreateTime));
    }

    default List<BankStatementDO> bankList(String fleet){
        QueryWrapper<BankStatementDO> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("id,id AS fleet");
        if(fleet!=null&&fleet!=""){
            queryWrapper.like("id", fleet);
        }
        return selectList(queryWrapper);
    }

    List<BankStatementDO> selectBankStatementPage(@Param("id") String id,
                                                  @Param("currencyType") Integer currencyType,
                                                  @Param("pageNo") Integer pageNo,
                                                  @Param("pageSize") Integer pageSize);

    List<BankStatementDO> selectBankStatement(@Param("id") String id, @Param("cardId") String cardId, @Param("currencyType") Integer currencyType);

    default Long selectCountById(String id) {
        return selectCount(new LambdaQueryWrapperX<BankStatementDO>()
                .eqIfPresent(BankStatementDO::getId, id));
    }

    BankStatementDO selectBankStatementItem(@Param("cardId") String cardId);

    BankStatementDO getBankAmountTotalByCardId(@Param("cardId") String cardId);

    @Update("UPDATE erp_bank_statement SET day_payment = 0, daily_expenses = 0")
    void resetDailyValues();

    List<BankStatementDO> selectDayReceiveMoney();

}